//
//  SetPasswordTableViewCell.m
//  GLGW_Shoping
//
//  Created by yang on 2018/11/17.
//  Copyright © 2018年 yang. All rights reserved.
//

#import "SetPasswordTableViewCell.h"

@implementation SetPasswordTableViewCell{
    GLGWView * lineView;
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        __block BOOL showPassword = YES;
        lineView = [[GLGWView alloc] initWithInSuperView:self.contentView];
        lineView.backgroundColor = [UIColor colorWithHexString:@"#EAEAEA"];
        [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView.mas_left).offset(kWidthProportion_In_iPhoneTriploid(30));
            make.right.equalTo(self.contentView.mas_right).offset(-kWidthProportion_In_iPhoneTriploid(30));
            make.bottom.equalTo(self.contentView.mas_bottom).offset(0);
            make.height.equalTo(@1);
        }];
        //
        GLGWTextField * loginInputTextField = [[GLGWTextField alloc] initWithFrame:CGRectMake(kWidthProportion_In_iPhoneTriploid(30), kHeightProportion_In_iPhoneTriploid(10), KScreenWidth - kWidthProportion_In_iPhoneTriploid(100), kHeightProportion_In_iPhoneTriploid(52)) titlePlaceholder:@"设置新密码（8-18位字母数字组合）" theFont:SYSTEMFONT(16) theTitColor:kColor_Rule_Black inSuperView:self];
        loginInputTextField.delegate = nil;
        loginInputTextField.clearButtonMode=UITextFieldViewModeWhileEditing;
        [loginInputTextField addTarget:self action:@selector(textField1TextChange:) forControlEvents:UIControlEventEditingChanged];
        [loginInputTextField addTarget:self action:@selector(textField1TextBegin:) forControlEvents:UIControlEventEditingDidBegin];
        [loginInputTextField addTarget:self action:@selector(textField1TextEndOnExit:) forControlEvents:UIControlEventEditingDidEnd];
        loginInputTextField.secureTextEntry = showPassword;
        //
        GLGWButton * seePosswordBut = [[GLGWButton alloc] initInSuperView:self.contentView];
        seePosswordBut.backgroundColor = kRandomColor;
        [[seePosswordBut rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
            showPassword = !showPassword;
            loginInputTextField.secureTextEntry = showPassword;
        }];
        [seePosswordBut mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.contentView.mas_right).offset(-kWidthProportion_In_iPhoneTriploid(15));
            make.top.equalTo(self.contentView.mas_top).offset(kHeightProportion_In_iPhoneTriploid(13));
            make.width.equalTo(@(kWidthProportion_In_iPhoneTriploid(50)));
            make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(46)));
        }];
        loginInputTextField.secureTextEntry = showPassword;
    }
    return self;
}

-(void)textField1TextChange:(GLGWTextField *)textField{
    if (self.delegate && [self.delegate respondsToSelector:@selector(inputPassword:)]) {
        [self.delegate inputPassword:textField.text];
    }
}

-(void)textField1TextBegin:(GLGWTextField *)textField{
    lineView.backgroundColor = kColor_Rule_Yellow;
}

-(void)textField1TextEndOnExit:(GLGWTextField *)textField{
    if (textField.text.length == 0) {
        lineView.backgroundColor = [UIColor colorWithHexString:@"#EAEAEA"];
    }else{
        lineView.backgroundColor = kColor_Rule_Yellow;
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
